﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Xml;
using SurveySystem.Model;
using System.Windows.Media;

namespace SurveySystem.Repository
{
    public class XmlSurveyRetrieverRepository : ISurveyRetrieverRepository
    {
        /// <summary>
        /// Default constructor
        /// </summary>
        public XmlSurveyRetrieverRepository() { }       

        /// <inheritdoc />
        public Survey RetrieveSurvey()
        {
#if DEBUG
            return new Survey()
            {
                SurveyID = 0,
                BackgroundColor = Colors.Azure,
                ForegroundColor = Colors.White,
                Closed = false,
                CloseDate = DateTime.Now.AddDays(5),
                OpenDate = DateTime.Now.AddDays(-2),
                Owner = "MEng Software Engineering 5",
                Description = "A simple test survey",
                MoreInfoUrl = "http://groups.google.com/group/hw-macs-interactive-displays",
                Title = "MEng Software Engineering 5 Survey",
            };
#else
            //TODO: Check file exists   
            try
            {
                var serializer = new XmlSerializer(typeof(Survey));
            
                //Must be the property which is set to fire the property changed event
                //TODO: Can we be more flexible with this xml file, e.g. filenames?
                var survey = (Survey)serializer.Deserialize(XmlReader.Create("SurveyModel.xml"));
                return survey;
            }
            catch (Exception e)
            {
                //TODO: Do something useful
            }
            return null;
#endif
        }
    }
}
